package com.game.majiang.vo;

import java.util.ArrayList;
import java.util.Random;

import javax.sql.rowset.CachedRowSet;

import com.game.majiang.config.DataManager;
import com.game.server.db.SqlHelper;

public class GameEndQuotationsVo {

	public  int id;
	public String content;
	
	public static ArrayList<GameEndQuotationsVo> getListGameEndQuotations() {
		ArrayList<GameEndQuotationsVo> list = new ArrayList<GameEndQuotationsVo>();
		String sql = "SELECT * FROM gameendquotations";
		CachedRowSet rs = SqlHelper.getResultSet(sql);
		try {
			while (rs.next()) {
				GameEndQuotationsVo geq = new GameEndQuotationsVo();
				geq.id = rs.getInt("id");
				geq.content = rs.getString("content");
				list.add(geq);
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
		
	}
	public static GameEndQuotationsVo getOneGameEndQuotations(GameEndQuotationsVo g) {
		
		ArrayList<GameEndQuotationsVo> list = DataManager.getInstance().getGeq();
		int size = list.size();
		if (size > 0) {
			if (size == 1) {
				return list.get(0);
			} else {
				GameEndQuotationsVo genqv = list.get(0);
				int i = 0;
				do {
					Random ran = new Random();
					int index = ran.nextInt(size);
					GameEndQuotationsVo geq = list.get(index);
					if (g == null) {
						genqv = geq;
						return genqv;
					} else if(geq.id != g.id) {
						genqv = geq;
						return genqv;
					}
					i++;
				} while (i != size);
				
			}
		}		
		return null;
	}
}
